/*
 *    Copyright (c) 2018-2025, daoism All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: daoism
 */

package com.mkh.st.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkh.st.admin.api.dto.BusinessPageDTO;
import com.mkh.st.admin.api.dto.BusinessSaveDTO;
import com.mkh.st.admin.api.dto.DeleteDto;
import com.mkh.st.admin.api.vo.BusinessPageVO;
import com.mkh.st.admin.api.vo.SiteInfoVO;
import com.mkh.st.admin.service.SysBusinessEntityService;
import com.mkh.st.common.core.util.R;
import com.mkh.st.common.log.annotation.SysLog;
import com.mkh.st.warehouse.vo.WarehouseFeignVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 业务实体表
 *
 * @author daoism code generator
 * @date 2021-07-06 09:27:05
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sysbusinessentity" )
@Api(value = "sysbusinessentity", tags = "业务实体表管理")
public class SysBusinessEntityController {

    private final SysBusinessEntityService sysBusinessEntityService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dto 查询条件
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R<IPage<BusinessPageVO>> getSysBusinessEntityPage(Page page,BusinessPageDTO dto) {
        return R.ok(sysBusinessEntityService.getSysBusinessEntityPage(page,dto));
    }

	@ApiOperation(value = "站点详情", notes = "站点详情")
	@GetMapping("/getSysBusinessDetail" )
	public R<BusinessPageVO> getSysBusinessDetail(@RequestParam Long businessId) {
		return R.ok(sysBusinessEntityService.getSysBusinessDetail(businessId));
	}

    /**
     * 删除站点
     * @param dto
     * @return R
     */
    @ApiOperation(value = "删除站点", notes = "删除站点")
    @PostMapping("/removeSite" )
    public R<Boolean> removeSite(@Valid @RequestBody DeleteDto dto) {
        return sysBusinessEntityService.removeSite(dto);
    }

    /**
     * 新增业务实体表
     * @param dto 业务实体信息集合
     * @return R
     */
    @ApiOperation(value = "保存子站点", notes = "保存子站点")
    @SysLog("保存子站点" )
    @PostMapping("/saveBusiness")
    public R<Boolean> saveBusiness(@Valid @RequestBody BusinessSaveDTO dto) {
        return R.ok(sysBusinessEntityService.saveBusiness(dto));
    }

	@ApiOperation(value = "业务线查询", notes = "业务线查询")
	@GetMapping("/getSiteInfoList" )
	public R<List<SiteInfoVO>> getSiteInfoList(@RequestParam String menuCode) {
		return R.ok(sysBusinessEntityService.getSiteInfo(menuCode));
	}

	@GetMapping("/getWarehouseList")
	@ApiOperation(value = "仓库列表", notes = "仓库列表")
	public R<List<WarehouseFeignVO>> getWarehouseList(@ApiParam(name = "menuCode", value = "菜单code",required = true) String menuCode,
													  @ApiParam(name = "siteId", value = "业务线id") Long siteId) {
		return R.ok(sysBusinessEntityService.getWarehouseList(menuCode,siteId));
	}

}
